package com.woniu.mgr.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.mgr.common.Result;
import com.woniu.mgr.controller.form.ApplyForModifyForm;
import com.woniu.mgr.controller.form.UpdateVenueApplyForm;
import com.woniu.mgr.model.VenueApply;
import com.woniu.mgr.service.VenueApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 场馆入驻申请表 前端控制器
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/venueApply")
@Slf4j
@Api(tags = "场馆入驻增删改查")
public class VenueApplyController {

    @Resource
    private VenueApplyService venueApplyService;


    @GetMapping("/queryAll")
    @ApiOperation("查询全部")
    public Result queryAll() {
        log.info("执行了查询全部操作");
        List<VenueApply> list = venueApplyService.list();
        return Result.success(200, "查询成功", list);
    }

    @GetMapping("/pageList")
    @ApiOperation("分页查询")
    public Result pageList(Integer page, Integer size) {
        log.info("执行了分页查询操作 {} {}", page,size);
        IPage<VenueApply> list = venueApplyService.list(page, size);
        return Result.success(200, "查询成功", list);
    }


    @PutMapping("/afModify")
    @ApiOperation("入驻申请修改全部")
    public Result afModify(ApplyForModifyForm applyForModifyForm) {
        log.info("执行了修改操作 {}", applyForModifyForm);
        venueApplyService.afModify(applyForModifyForm);
        return Result.success(200, "修改成功", null);
    }

    @PutMapping("/updateVenueApply")
    @ApiOperation("修改状态")
    public Result updateVenueApply(@RequestBody UpdateVenueApplyForm updateVenueApplyForm) {
        VenueApply byId = venueApplyService.getById(updateVenueApplyForm.getVenueApplyId());
        byId.setState("通过");
        venueApplyService.updateById(byId);
        return Result.success(200, "申请通过", null);
    }

    @PutMapping("/updateState")
    @ApiOperation("修改状态")
    public Result updateState(@RequestBody UpdateVenueApplyForm updateVenueApplyForm) {
        VenueApply byId = venueApplyService.getById(updateVenueApplyForm.getVenueApplyId());
        VenueApply byId1 = venueApplyService.getById(updateVenueApplyForm.getMessage());
        byId.setState("驳回");
        byId1.setMessage(updateVenueApplyForm.getMessage());
        venueApplyService.updateById(byId);
        venueApplyService.updateById(byId1);
        return Result.success(200, "驳回申请", null);
    }

}

